// ignore_for_file: constant_identifier_names

part of 'date_util.dart';

enum DateFormatType { ymd, hms, ymdhms }

class DateFormat {
  static String format(
    DateTime date,
    DateFormatType type, {
    String dateSeprator = '-',
    String timeSeprator = ':',
    bool isUnit = false,
  }) {
    var delta =
        DateTime.fromMillisecondsSinceEpoch(date.millisecondsSinceEpoch);
    var _year = delta.year.toString();
    var _month = delta.month.toString().padLeft(2, '0');
    var _day = delta.day.toString().padLeft(2, '0');
    var _hour = delta.hour.toString().padLeft(2, '0');
    var _minute = delta.minute.toString().padLeft(2, '0');
    var _seconds = delta.second.toString().padLeft(2, '0');

    switch (type) {
      case DateFormatType.ymd:
        if (isUnit) {
          return '$_year年$_month月$_day日';
        }
        return '$_year$dateSeprator$_month$dateSeprator$_day';
      case DateFormatType.hms:
        if (isUnit) {
          return '$_hour小时$_minute分钟$_seconds秒';
        }
        return '$_hour$timeSeprator$_minute$timeSeprator$_seconds';
      default:
        if (isUnit) {
          return '$_year年$_month月$_day日 $_hour小时$_minute分钟$_seconds秒';
        }
        return '$_year$dateSeprator$_month$dateSeprator$_day $_hour$timeSeprator$_minute$timeSeprator$_seconds';
    }
  }
}
